<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.2.1.min.js"></script>
    <script>
        function addEmployee() {
            $.post("/employee/reg",$("#f1").serialize(),function (info) {
               if(info == "ok"){
                   $("#errorDiv").html("添加成功");
               }
               else{
                   //将json字符串转化为json对象
                   var errorList = JSON.parse(info);
                   var str = "";
                   for(var i=0;i<errorList.length;i++){
                       var obj = errorList[i];
                       str +=  `属性名：${obj.field}，错误信息：${obj.defaultMessage}<br>`;
                   }
                   $("#errorDiv").html(str);
               }
            });
        }

        function updateEmployee() {
            $.post("/employee/update",$("#updateForm").serialize(),function (info) {
                if(info == "ok"){
                    $("#errorDiv").html("添加成功");
                }
                else{
                    //将json字符串转化为json对象
                    var errorList = JSON.parse(info);
                    var str = "";
                    for(var i=0;i<errorList.length;i++){
                        var obj = errorList[i];
                        str +=  `属性名：${obj.field}，错误信息：${obj.defaultMessage}<br>`;
                    }
                    $("#updateErrorDiv").html(str);
                }
            });
        }
    </script>
</head>
<body>

    添加员工
    <div id="errorDiv"></div>
    <form id="f1">
        姓名：<input type="text" name="name"><br>
        工资：<input type="number" name="money"><br>
        电话：<input type="text" name="tel"><br>
        邮件：<input type="text" name="email"><br>
        <input type="button" value="添加员工" onclick="addEmployee()">
    </form>
    <hr>
    <div id="updateErrorDiv"></div>
    <form id="updateForm">
        密码：<input type="text" name="pwd"><br>
        工资：<input type="number" name="money"><br>
        <input type="button" value="修改员工" onclick="updateEmployee()">
    </form>
</body>
</html>